home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / language / embedded / ibm / ashc5.arc / PSEUDO.C < prev    next >
C/C++ Source or Header  |  1990-07-15  |  7KB  |  196 lines

  1. /*
  2.  *      pseudo --- pseudo op processing
  3.  */
  4.  
  5. #define RMB     0       /* Reserve Memory Bytes         */
  6. #define FCB     1       /* Form Constant Bytes          */
  7. #define FDB     2       /* Form Double Bytes (words)    */
  8. #define FCC     3       /* Form Constant Characters     */
  9. #define ORG     4       /* Origin                       */
  10. #define EQU     5       /* Equate                       */
  11. #define ZMB     6       /* Zero memory bytes            */
  12. #define FILL    7       /* block fill constant bytes    */
  13. #define OPT     8       /* assembler option             */
  14. #define NULL_OP 9       /* null pseudo op               */
  15. #define PAGE    10      /* new page                     */
  16. #define END     11      /* end directive                */
  17.  
  18. struct oper pseudo[] = {
  19. "bsz",  PSEUDO, ZMB,    0,
  20. "end",  PSEUDO, END,    0,
  21. "equ",  PSEUDO, EQU,    0,
  22. "fcb",  PSEUDO, FCB,    0,
  23. "fcc",  PSEUDO, FCC,    0,
  24. "fdb",  PSEUDO, FDB,    0,
  25. "fill", PSEUDO, FILL,   0,
  26. "nam",  PSEUDO, NULL_OP,0,
  27. "name", PSEUDO, NULL_OP,0,
  28. "opt",  PSEUDO, OPT,    0,
  29. "org",  PSEUDO, ORG,    0,
  30. "pag",  PSEUDO, PAGE,   0,
  31. "page", PSEUDO, PAGE,   0,
  32. "rmb",  PSEUDO, RMB,    0,
  33. "spc",  PSEUDO, NULL_OP,0,
  34. "ttl",  PSEUDO, NULL_OP,0,
  35. "zmb",  PSEUDO, ZMB,    0
  36. };
  37.  
  38. /*
  39.  *      do_pseudo --- do pseudo op processing
  40.  */
  41. do_pseudo(op)
  42. int op; /* which op */
  43. {
  44.         char    fccdelim;
  45.         int     j;
  46.         int     fill;
  47.         char    *skip_white();
  48.  
  49.         if( op != EQU && *Label )
  50.                 install(Label,Pc);
  51.  
  52.         P_force++;
  53.         switch(op){
  54.                 case RMB:                       /* reserve memory bytes */
  55.                         if( eval() ){
  56.                                 Pc +=  Result;
  57.                                 f_record();     /* flush out bytes */
  58.                                 }
  59.                         break;
  60.                 case ZMB:                       /* zero memory bytes */
  61.             if( eval() ) {
  62.                 if( Result > P_LIMIT )
  63.                     note("Many bytes; listing abbreviated");
  64.                                 while( Result-- )
  65.                     emit(0);
  66.                 }
  67.                         break;
  68.                 case FILL:                      /* fill memory with constant */
  69.             eval();
  70.                         fill = Result;
  71.                         if( *Optr++ != ',' )
  72.                 error("Missing comma in fill statement");
  73.                         else{
  74.                                 Optr = skip_white(Optr);
  75.                 if( !eval() ) break;
  76.                 if( Result > P_LIMIT )
  77.                     note("Many bytes; listing abbreviated");
  78.                                 while( Result-- )
  79.                                         emit(fill);
  80.                                 }
  81.                         break;
  82.                 case FCB:                       /* form constant byte(s) */
  83.                         do{
  84.                                 Optr = skip_white(Optr);
  85.                 eval();
  86.                 if( Result > 0xFF ){
  87.                                         if(!Force_byte)
  88.                                                 warn("Value truncated");
  89.                                         Result = lobyte(Result);
  90.                                         }
  91.                                 emit(Result);
  92.                         }while( *Optr++ == ',' );
  93.                         break;
  94.                 case FDB:                       /* form double byte(s) */
  95.                         do{
  96.                                 Optr = skip_white(Optr);
  97.                 eval();
  98.                                 eword(Result);
  99.                         }while( *Optr++ == ',' );
  100.                         break;
  101.                 case FCC:                       /* form constant characters */
  102.             if( delim(*Optr) ) {
  103.                 error("No characters specified");
  104.                 break;
  105.                 }
  106.                         fccdelim = *Optr++;
  107.                         while( *Optr != EOS && *Optr != fccdelim)
  108.                                 emit(*Optr++);
  109.             if(*Optr != fccdelim)
  110.                                 error("Missing Delimiter");
  111.                         break;
  112.                 case ORG:                       /* origin */
  113.                         if( eval() ){
  114.                                 Old_pc = Pc = Result;
  115.                                 f_record();     /* flush out any bytes */
  116.                                 }
  117.                         break;
  118.                 case EQU:                       /* equate */
  119.                         if(*Label==EOS){
  120.                                 error("EQU requires label");
  121.                                 break;
  122.                                 }
  123.             eval();
  124.             install(Label,Result);
  125.             Old_pc = Result;        /* override normal */
  126.                 /* above makes Result show on listing */
  127.                         break;
  128.                 case OPT:                       /* assembler option */
  129.             P_force=0;
  130.             for( j=0; Operand[j]; j++ )
  131.                Operand[j] = mapdn( Operand[j] );
  132.             if( Lflag ) Cpflag |= 2;
  133.                         do {
  134.                             Optr = skip_white(Optr);
  135.                 if( head(Optr,"l") )
  136.                                     Lflag=1;
  137.                 else if( head(Optr,"nol"))
  138.                                     Lflag=0;
  139.                 else if( head(Optr,"c")){
  140.                                     Cflag=1;
  141.                                     Ctotal=0;
  142.                                     }
  143.                 else if( head(Optr,"noc")) {
  144.                     Cflag=0;
  145.                     Cpflag |= 1;
  146.                     }
  147.                 else if( head(Optr,"contc"))
  148.                                     Cflag=1;
  149.                 else if ( head(Optr,"s"))
  150.                                     Sflag = 1;
  151.                 else if ( head(Optr,"cre"))
  152.                                     CREflag = 1;
  153.                             else
  154.                                     error("Unrecognized or missing OPT");
  155.                 while( alpha(*Optr) ) Optr++;
  156.                         } while( *Optr++ == ',' );
  157.                         break;
  158.                 case PAGE:                      /* go to a new page */
  159.                         P_force=0;
  160.                         N_page = 1;
  161.             if (Pass == 2 )
  162.                          if (Lflag)  
  163.                           {
  164.                            printf ("\f");
  165.                printf ("%-40s",Argv[Cfn]);
  166.                printf ("     ");
  167.                            printf ("page %3d\n",Page_num++);
  168.               }
  169.             break;
  170.         case END:               /* END directive */
  171.             End = YES;
  172.             if( !delim(*Optr) ) {
  173.                if( eval() ) {
  174.                   if((unsigned int)Result > (unsigned int)0xFFFF)
  175.                  error("Entry point value > 16 bits");
  176.                   if( Entry_set ) {
  177.                  if( Result == Entry_pt )
  178.                     warn("Entry point already specified");
  179.                  else error("Entry point redefined");
  180.                   }
  181.                   else {
  182.                  Entry_pt = Result;
  183.                  Entry_set = YES;
  184.                   }
  185.                }
  186.                else warn("Comments following END should start with semicolon");
  187.             }
  188.             break;
  189.                 case NULL_OP:                   /* ignored psuedo ops */
  190.                         P_force=0;
  191.                         break;
  192.                 default:
  193.                         fatal("Pseudo error");
  194.                 }
  195. }
  196.